{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# AWS Step Functions Data Science SDK - Hello World\n",
    "1. [Introduction](#Introduction)\n",
    "1. [Setup](#Setup)\n",
    "1. [Create steps for your workflow](#Create-steps-for-your-workflow)\n",
    "1. [Define the workflow instance](#Define-the-workflow-instance)\n",
    "1. [Review the Amazon States Language code for your workflow](#Review-the-Amazon-States-Language-code-for-your-workflow)\n",
    "1. [Create the workflow on AWS Step Functions](#Create-the-workflow-on-AWS-Step-Functions)\n",
    "1. [Execute the workflow](#Execute-the-workflow)\n",
    "1. [Review the execution progress](#Review-the-execution-progress)\n",
    "1. [Review the execution history](#Review-the-execution-history)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction\n",
    "\n",
    "This notebook describes using the AWS Step Functions Data Science SDK to create and manage workflows. The Step Functions SDK is an open source library that allows data scientists to easily create and execute machine learning workflows using AWS Step Functions and Amazon SageMaker. For more information, see the following.\n",
    "* [AWS Step Functions](https://aws.amazon.com/step-functions/)\n",
    "* [AWS Step Functions Developer Guide](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html)\n",
    "* [AWS Step Functions Data Science SDK](https://aws-step-functions-data-science-sdk.readthedocs.io)\n",
    "\n",
    "In this notebook we will use the SDK to create steps, link them together to create a workflow, and execute the workflow in AWS Step Functions. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already up-to-date: stepfunctions in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (1.0.0.3)\n",
      "Requirement not upgraded as not directly required: pyyaml in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from stepfunctions) (3.12)\n",
      "Requirement not upgraded as not directly required: boto3>=1.9.213 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from stepfunctions) (1.10.19)\n",
      "Requirement not upgraded as not directly required: sagemaker>=1.42.8 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from stepfunctions) (1.45.0.dev0)\n",
      "Requirement not upgraded as not directly required: jmespath<1.0.0,>=0.7.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from boto3>=1.9.213->stepfunctions) (0.9.4)\n",
      "Requirement not upgraded as not directly required: botocore<1.14.0,>=1.13.19 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from boto3>=1.9.213->stepfunctions) (1.13.19)\n",
      "Requirement not upgraded as not directly required: s3transfer<0.3.0,>=0.2.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from boto3>=1.9.213->stepfunctions) (0.2.1)\n",
      "Requirement not upgraded as not directly required: numpy>=1.9.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from sagemaker>=1.42.8->stepfunctions) (1.14.3)\n",
      "Requirement not upgraded as not directly required: requests<2.21,>=2.20.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from sagemaker>=1.42.8->stepfunctions) (2.20.0)\n",
      "Requirement not upgraded as not directly required: protobuf3-to-dict>=0.1.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from sagemaker>=1.42.8->stepfunctions) (0.1.5)\n",
      "Requirement not upgraded as not directly required: protobuf>=3.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from sagemaker>=1.42.8->stepfunctions) (3.6.1)\n",
      "Requirement not upgraded as not directly required: scipy>=0.19.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from sagemaker>=1.42.8->stepfunctions) (1.1.0)\n",
      "Requirement not upgraded as not directly required: smdebug-rulesconfig==0.1.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from sagemaker>=1.42.8->stepfunctions) (0.1.2)\n",
      "Requirement not upgraded as not directly required: urllib3<1.26,>=1.20; python_version >= \"3.4\" in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from botocore<1.14.0,>=1.13.19->boto3>=1.9.213->stepfunctions) (1.23)\n",
      "Requirement not upgraded as not directly required: docutils<0.16,>=0.10 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from botocore<1.14.0,>=1.13.19->boto3>=1.9.213->stepfunctions) (0.14)\n",
      "Requirement not upgraded as not directly required: python-dateutil<2.8.1,>=2.1; python_version >= \"2.7\" in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from botocore<1.14.0,>=1.13.19->boto3>=1.9.213->stepfunctions) (2.7.3)\n",
      "Requirement not upgraded as not directly required: idna<2.8,>=2.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from requests<2.21,>=2.20.0->sagemaker>=1.42.8->stepfunctions) (2.6)\n",
      "Requirement not upgraded as not directly required: certifi>=2017.4.17 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from requests<2.21,>=2.20.0->sagemaker>=1.42.8->stepfunctions) (2019.9.11)\n",
      "Requirement not upgraded as not directly required: chardet<3.1.0,>=3.0.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from requests<2.21,>=2.20.0->sagemaker>=1.42.8->stepfunctions) (3.0.4)\n",
      "Requirement not upgraded as not directly required: six in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from protobuf3-to-dict>=0.1.5->sagemaker>=1.42.8->stepfunctions) (1.11.0)\n",
      "Requirement not upgraded as not directly required: setuptools in /home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages (from protobuf>=3.1->sagemaker>=1.42.8->stepfunctions) (39.1.0)\n",
      "\u001b[33mYou are using pip version 10.0.1, however version 19.3.1 is available.\n",
      "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "!{sys.executable} -m pip install --upgrade stepfunctions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "### Add a policy to your SageMaker role in IAM\n",
    "\n",
    "**If you are running this notebook on an Amazon SageMaker notebook instance**, the IAM role assumed by your notebook instance needs permission to create and run workflows in AWS Step Functions. To provide this permission to the role, do the following.\n",
    "\n",
    "1. Open the Amazon [SageMaker console](https://console.aws.amazon.com/sagemaker/). \n",
    "2. Select **Notebook instances** and choose the name of your notebook instance\n",
    "3. Under **Permissions and encryption** select the role ARN to view the role on the IAM console\n",
    "4. Choose **Attach policies** and search for `AWSStepFunctionsFullAccess`.\n",
    "5. Select the check box next to `AWSStepFunctionsFullAccess` and choose **Attach policy**\n",
    "\n",
    "If you are running this notebook in a local environment, the SDK will use your configured AWS CLI configuration. For more information, see [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).\n",
    "\n",
    "Next, create an execution role in IAM for Step Functions. \n",
    "\n",
    "### Create an execution role for Step Functions\n",
    "\n",
    "You need an execution role so that you can create and execute workflows in Step Functions.\n",
    "\n",
    "1. Go to the [IAM console](https://console.aws.amazon.com/iam/)\n",
    "2. Select **Roles** and then **Create role**.\n",
    "3. Under **Choose the service that will use this role** select **Step Functions**\n",
    "4. Choose **Next** until you can enter a **Role name**\n",
    "5. Enter a name such as `StepFunctionsWorkflowExecutionRole` and then select **Create role**\n",
    "\n",
    "\n",
    "Attach a policy to the role you created. The following steps attach a policy that provides full access to Step Functions, however as a good practice you should only provide access to the resources you need.  \n",
    "\n",
    "1. Under the **Permissions** tab, click **Add inline policy**\n",
    "2. Enter the following in the **JSON** tab\n",
    "\n",
    "```json\n",
    "{\n",
    "    \"Version\": \"2012-10-17\",\n",
    "    \"Statement\": [\n",
    "        {\n",
    "            \"Effect\": \"Allow\",\n",
    "            \"Action\": [\n",
    "                \"sagemaker:CreateTransformJob\",\n",
    "                \"sagemaker:DescribeTransformJob\",\n",
    "                \"sagemaker:StopTransformJob\",\n",
    "                \"sagemaker:CreateTrainingJob\",\n",
    "                \"sagemaker:DescribeTrainingJob\",\n",
    "                \"sagemaker:StopTrainingJob\",\n",
    "                \"sagemaker:CreateHyperParameterTuningJob\",\n",
    "                \"sagemaker:DescribeHyperParameterTuningJob\",\n",
    "                \"sagemaker:StopHyperParameterTuningJob\",\n",
    "                \"sagemaker:CreateModel\",\n",
    "                \"sagemaker:CreateEndpointConfig\",\n",
    "                \"sagemaker:CreateEndpoint\",\n",
    "                \"sagemaker:DeleteEndpointConfig\",\n",
    "                \"sagemaker:DeleteEndpoint\",\n",
    "                \"sagemaker:UpdateEndpoint\",\n",
    "                \"sagemaker:ListTags\",\n",
    "                \"lambda:InvokeFunction\",\n",
    "                \"sqs:SendMessage\",\n",
    "                \"sns:Publish\",\n",
    "                \"ecs:RunTask\",\n",
    "                \"ecs:StopTask\",\n",
    "                \"ecs:DescribeTasks\",\n",
    "                \"dynamodb:GetItem\",\n",
    "                \"dynamodb:PutItem\",\n",
    "                \"dynamodb:UpdateItem\",\n",
    "                \"dynamodb:DeleteItem\",\n",
    "                \"batch:SubmitJob\",\n",
    "                \"batch:DescribeJobs\",\n",
    "                \"batch:TerminateJob\",\n",
    "                \"glue:StartJobRun\",\n",
    "                \"glue:GetJobRun\",\n",
    "                \"glue:GetJobRuns\",\n",
    "                \"glue:BatchStopJobRun\"\n",
    "            ],\n",
    "            \"Resource\": \"*\"\n",
    "        },\n",
    "        {\n",
    "            \"Effect\": \"Allow\",\n",
    "            \"Action\": [\n",
    "                \"iam:PassRole\"\n",
    "            ],\n",
    "            \"Resource\": \"*\",\n",
    "            \"Condition\": {\n",
    "                \"StringEquals\": {\n",
    "                    \"iam:PassedToService\": \"sagemaker.amazonaws.com\"\n",
    "                }\n",
    "            }\n",
    "        },\n",
    "        {\n",
    "            \"Effect\": \"Allow\",\n",
    "            \"Action\": [\n",
    "                \"events:PutTargets\",\n",
    "                \"events:PutRule\",\n",
    "                \"events:DescribeRule\"\n",
    "            ],\n",
    "            \"Resource\": [\n",
    "                \"arn:aws:events:*:*:rule/StepFunctionsGetEventsForSageMakerTrainingJobsRule\",\n",
    "                \"arn:aws:events:*:*:rule/StepFunctionsGetEventsForSageMakerTransformJobsRule\",\n",
    "                \"arn:aws:events:*:*:rule/StepFunctionsGetEventsForSageMakerTuningJobsRule\",\n",
    "                \"arn:aws:events:*:*:rule/StepFunctionsGetEventsForECSTaskRule\",\n",
    "                \"arn:aws:events:*:*:rule/StepFunctionsGetEventsForBatchJobsRule\"\n",
    "            ]\n",
    "        }\n",
    "    ]\n",
    "}\n",
    "```\n",
    "\n",
    "3. Choose **Review policy** and give the policy a name such as `StepFunctionsWorkflowExecutionPolicy`\n",
    "4. Choose **Create policy**. You will be redirected to the details page for the role.\n",
    "5. Copy the **Role ARN** at the top of the **Summary**\n",
    "\n",
    "### Import the required modules from the SDK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import stepfunctions\n",
    "import logging\n",
    "\n",
    "from stepfunctions.steps import *\n",
    "from stepfunctions.workflow import Workflow\n",
    "\n",
    "stepfunctions.set_stream_logger(level=logging.INFO)\n",
    "\n",
    "workflow_execution_role = \"arn:aws:iam::806570384721:role/StepFunctionsExecutionRole\" \n",
    "# paste the StepFunctionsWorkflowExecutionRole ARN from above\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create basic workflow\n",
    "\n",
    "In the following cell, you will define the step that you will use in our first workflow.  Then you will create, visualize and execute the workflow. \n",
    "\n",
    "Steps relate to states in AWS Step Functions. For more information, see [States](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-states.html) in the *AWS Step Functions Developer Guide*. For more information on the AWS Step Functions Data Science SDK APIs, see: https://aws-step-functions-data-science-sdk.readthedocs.io. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pass state\n",
    "\n",
    "A `Pass` state in Step Functions simply passes its input to its output, without performing work. See [Pass](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/states.html#stepfunctions.steps.states.Pass) in the AWS Step Functions Data Science SDK documentation.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "start_pass_state = Pass(\n",
    "    state_id=\"MyPassState\"             \n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Chain together steps for the basic path\n",
    "\n",
    "The following cell links together the steps you've created into a sequential group called `basic_path`. We will chain a single step to create our basic path. See [Chain](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/states.html#stepfunctions.steps.states.Chain) in the AWS Step Functions Data Science SDK documentation.\n",
    "\n",
    "After chaining together the steps for the basic path, in this case only one step, we will visualize the basic path."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# First we chain the start pass state\n",
    "basic_path=Chain([start_pass_state])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define the workflow instance\n",
    "\n",
    "The following cell defines the [workflow](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Workflow) with the path we just defined.\n",
    "\n",
    "After defining the workflow, we will render the graph to see what our workflow looks like."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://do0of8uwbahzz.cloudfront.net/graph.css\">\n",
       "<div id=\"graph-614\" class=\"workflowgraph\">\n",
       "    \n",
       "    <svg></svg>\n",
       "    \n",
       "</div>\n",
       "\n",
       "<script type=\"text/javascript\">\n",
       "\n",
       "require.config({\n",
       "    paths: {\n",
       "        sfn: \"https://do0of8uwbahzz.cloudfront.net/sfn\",\n",
       "    }\n",
       "});\n",
       "\n",
       "require(['sfn'], function(sfn) {\n",
       "    var options = {\n",
       "        width: $('#graph-614').width(),\n",
       "        height: 600,\n",
       "        layout: 'LR',\n",
       "        resizeHeight: true\n",
       "    };\n",
       "\n",
       "    var definition = {\"StartAt\": \"MyPassState\", \"States\": {\"MyPassState\": {\"Type\": \"Pass\", \"End\": true}}};\n",
       "    var elementId = '#graph-614';\n",
       "\n",
       "    var graph = new sfn.StateMachineGraph(definition, elementId, options);\n",
       "    graph.render();\n",
       "});\n",
       "\n",
       "</script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Next, we define the workflow\n",
    "basic_workflow = Workflow(\n",
    "    name=\"MyWorkflow_Simple\",\n",
    "    definition=basic_path,\n",
    "    role=workflow_execution_role\n",
    ")\n",
    "\n",
    "#Render the workflow\n",
    "basic_workflow.render_graph()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Review the Amazon States Language code for your workflow\n",
    "\n",
    "The following renders the JSON of the [Amazon States Language](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html) definition of the workflow you created. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "    \"StartAt\": \"MyPassState\",\n",
      "    \"States\": {\n",
      "        \"MyPassState\": {\n",
      "            \"Type\": \"Pass\",\n",
      "            \"End\": true\n",
      "        }\n",
      "    }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "print(basic_workflow.definition.to_json(pretty=True))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create the workflow on AWS Step Functions\n",
    "\n",
    "Create the workflow in AWS Step Functions with [create](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Workflow.create)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32m[INFO] Workflow created successfully on AWS Step Functions.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'arn:aws:states:us-east-1:806570384721:stateMachine:MyWorkflow_Simple'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "basic_workflow.create()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Execute the workflow\n",
    "\n",
    "Run the workflow with [execute](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Workflow.execute). Since the workflow only has a pass state, it will succeed immediately."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32m[INFO] Workflow execution started successfully on AWS Step Functions.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "basic_workflow_execution = basic_workflow.execute()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Review the execution progress\n",
    "\n",
    "Render workflow progress with the [render_progress](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Execution.render_progress).\n",
    "\n",
    "This generates a snapshot of the current state of your workflow as it executes. This is a static image. Run the cell again to check progress. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://do0of8uwbahzz.cloudfront.net/graph.css\">\n",
       "<div id=\"graph-835\" class=\"workflowgraph\">\n",
       "    \n",
       "    <style>\n",
       "        .graph-legend ul {\n",
       "            list-style-type: none;\n",
       "            padding: 10px;\n",
       "            padding-left: 0;\n",
       "            margin: 0;\n",
       "            position: absolute;\n",
       "            top: 0;\n",
       "            background: transparent;\n",
       "        }\n",
       "\n",
       "        .graph-legend li {\n",
       "            margin-left: 10px;\n",
       "            display: inline-block;\n",
       "        }\n",
       "\n",
       "        .graph-legend li > div {\n",
       "            width: 10px;\n",
       "            height: 10px;\n",
       "            display: inline-block;\n",
       "        }\n",
       "\n",
       "        .graph-legend .success { background-color: #2BD62E }\n",
       "        .graph-legend .failed { background-color: #DE322F }\n",
       "        .graph-legend .cancelled { background-color: #DDDDDD }\n",
       "        .graph-legend .in-progress { background-color: #53C9ED }\n",
       "        .graph-legend .caught-error { background-color: #FFA500 }\n",
       "    </style>\n",
       "    <div class=\"graph-legend\">\n",
       "        <ul>\n",
       "            <li>\n",
       "                <div class=\"success\"></div>\n",
       "                <span>Success</span>\n",
       "            </li>\n",
       "            <li>\n",
       "                <div class=\"failed\"></div>\n",
       "                <span>Failed</span>\n",
       "            </li>\n",
       "            <li>\n",
       "                <div class=\"cancelled\"></div>\n",
       "                <span>Cancelled</span>\n",
       "            </li>\n",
       "            <li>\n",
       "                <div class=\"in-progress\"></div>\n",
       "                <span>In Progress</span>\n",
       "            </li>\n",
       "            <li>\n",
       "                <div class=\"caught-error\"></div>\n",
       "                <span>Caught Error</span>\n",
       "            </li>\n",
       "        </ul>\n",
       "    </div>\n",
       "\n",
       "    <svg></svg>\n",
       "    <a href=\"https://console.aws.amazon.com/states/home?region=us-east-1#/executions/details/arn:aws:states:us-east-1:806570384721:execution:MyWorkflow_Simple:9f787274-ca42-48bc-8a85-f2cf8f8e7967\" target=\"_blank\"> Inspect in AWS Step Functions </a>\n",
       "</div>\n",
       "\n",
       "<script type=\"text/javascript\">\n",
       "\n",
       "require.config({\n",
       "    paths: {\n",
       "        sfn: \"https://do0of8uwbahzz.cloudfront.net/sfn\",\n",
       "    }\n",
       "});\n",
       "\n",
       "require(['sfn'], function(sfn) {\n",
       "    var options = {\n",
       "        width: $('#graph-835').width(),\n",
       "        height: 1000,\n",
       "        layout: 'LR',\n",
       "        resizeHeight: true\n",
       "    };\n",
       "\n",
       "    var definition = {\"StartAt\": \"MyPassState\", \"States\": {\"MyPassState\": {\"Type\": \"Pass\", \"End\": true}}};\n",
       "    var elementId = '#graph-835';\n",
       "    var events = { 'events': [{\"timestamp\": 1579010546.823, \"type\": \"ExecutionStarted\", \"id\": 1, \"previousEventId\": 0, \"executionStartedEventDetails\": {\"input\": \"{}\", \"roleArn\": \"arn:aws:iam::806570384721:role/StepFunctionsExecutionRole\"}}, {\"timestamp\": 1579010546.847, \"type\": \"PassStateEntered\", \"id\": 2, \"previousEventId\": 0, \"stateEnteredEventDetails\": {\"name\": \"MyPassState\", \"input\": \"{}\"}}, {\"timestamp\": 1579010546.847, \"type\": \"PassStateExited\", \"id\": 3, \"previousEventId\": 2, \"stateExitedEventDetails\": {\"name\": \"MyPassState\", \"output\": \"{}\"}}, {\"timestamp\": 1579010546.847, \"type\": \"ExecutionSucceeded\", \"id\": 4, \"previousEventId\": 3, \"executionSucceededEventDetails\": {\"output\": \"{}\"}}] };\n",
       "\n",
       "    var graph = new sfn.StateMachineExecutionGraph(definition, events, elementId, options);\n",
       "    graph.render();\n",
       "});\n",
       "\n",
       "</script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "basic_workflow_execution.render_progress()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Review the execution history\n",
    "\n",
    "Use [list_events](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Execution.list_events) to list all events in the workflow execution."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <style>\n",
       "        \n",
       "    .table-widget {\n",
       "        width: 100%;\n",
       "        font-size: 14px;\n",
       "        line-height: 28px;\n",
       "        color: #545b64;\n",
       "        border-spacing: 0;\n",
       "        background-color: #fff;\n",
       "        border-color: grey;\n",
       "        background: #fafafa;\n",
       "    }\n",
       "\n",
       "    .table-widget thead th {\n",
       "        text-align: left !important;\n",
       "        color: #879596;\n",
       "        padding: 0.3em 2em;\n",
       "        border-bottom: 1px solid #eaeded;\n",
       "        min-height: 4rem;\n",
       "        line-height: 28px;\n",
       "    }\n",
       "\n",
       "    .table-widget thead th:first-of-type {\n",
       "    }\n",
       "\n",
       "    .table-widget td {\n",
       "        overflow-wrap: break-word;\n",
       "        padding: 0.4em 2em;\n",
       "        line-height: 28px;\n",
       "        text-align: left !important;\n",
       "        background: #fff;\n",
       "        border-bottom: 1px solid #eaeded;\n",
       "        border-top: 1px solid transparent;\n",
       "    }\n",
       "\n",
       "    .table-widget td:before {\n",
       "        content: \"\";\n",
       "        height: 3rem;\n",
       "    }\n",
       "\n",
       "    a {\n",
       "        cursor: pointer;\n",
       "        text-decoration: none !important;\n",
       "        color: #007dbc;\n",
       "    }\n",
       "\n",
       "    a:hover {\n",
       "        text-decoration: underline !important;\n",
       "    }\n",
       "\n",
       "    a.disabled {\n",
       "        color: black;\n",
       "        cursor: default;\n",
       "        pointer-events: none;\n",
       "    }\n",
       "\n",
       "    .hide {\n",
       "        display: none;\n",
       "    }\n",
       "\n",
       "    pre {\n",
       "        white-space: pre-wrap;\n",
       "    }\n",
       "\n",
       "        \n",
       "    .table-widget .clickable-cell {\n",
       "        padding-left: 0.1em;\n",
       "        cursor: pointer;\n",
       "    }\n",
       "\n",
       "    .toggle-icon {\n",
       "        display: inline-block;\n",
       "        width: 0;\n",
       "        height: 0;\n",
       "        border-top: 5px solid transparent;\n",
       "        border-left: 8px solid #545b64;\n",
       "        border-bottom: 5px solid transparent;\n",
       "        margin-right: 5px;\n",
       "    }\n",
       "\n",
       "    .toggle-icon.open {\n",
       "        -webkit-transform: rotate(90deg);\n",
       "        -ms-transform: rotate(90deg);\n",
       "        transform: rotate(90deg);\n",
       "    }\n",
       "\n",
       "    </style>\n",
       "    <table class=\"table-widget\">\n",
       "        <thead>\n",
       "            <tr>\n",
       "                <th style=\"width: 60px\">ID</th>\n",
       "                <th>Type</th>\n",
       "                <th>Step</th>\n",
       "                <th>Resource</th>\n",
       "                <th>Elapsed Time (ms)</th>\n",
       "                <th>Timestamp</th>\n",
       "            </tr>\n",
       "        </thead>\n",
       "        <tbody>\n",
       "            \n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>1</span>\n",
       "        </td>\n",
       "        <td>ExecutionStarted</td>\n",
       "        <td></td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>0.0</td>\n",
       "        <td>Jan 14, 2020 02:02:26.823 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"input\": {},\n",
       "    \"roleArn\": \"arn:aws:iam::806570384721:role/StepFunctionsExecutionRole\"\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>2</span>\n",
       "        </td>\n",
       "        <td>PassStateEntered</td>\n",
       "        <td>MyPassState</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>24.0</td>\n",
       "        <td>Jan 14, 2020 02:02:26.847 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"MyPassState\",\n",
       "    \"input\": {}\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>3</span>\n",
       "        </td>\n",
       "        <td>PassStateExited</td>\n",
       "        <td>MyPassState</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>24.0</td>\n",
       "        <td>Jan 14, 2020 02:02:26.847 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"MyPassState\",\n",
       "    \"output\": {}\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>4</span>\n",
       "        </td>\n",
       "        <td>ExecutionSucceeded</td>\n",
       "        <td></td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>24.0</td>\n",
       "        <td>Jan 14, 2020 02:02:26.847 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"output\": {}\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "        </tbody>\n",
       "    </table>\n",
       "    <script type=\"text/javascript\">\n",
       "        \n",
       "    var clickableCells = document.getElementsByClassName(\"clickable-cell\");\n",
       "    for (var cell of clickableCells) {\n",
       "        cell.addEventListener(\"click\", function(e) {\n",
       "            var currentRow = e.srcElement.closest(\"tr\");\n",
       "            var toggleRow = currentRow.nextElementSibling;\n",
       "            var toggleArrow = currentRow.getElementsByClassName(\"toggle-icon\")[0];\n",
       "\n",
       "            toggleRow.classList.toggle(\"hide\");\n",
       "            toggleArrow.classList.toggle(\"open\");\n",
       "        });\n",
       "    }\n",
       "\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "basic_workflow_execution.list_events(html=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create additional steps for your workflow\n",
    "\n",
    "In the following cells, you will define additional steps that you will use in our workflows. Steps relate to states in AWS Step Functions. For more information, see [States](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-states.html) in the *AWS Step Functions Developer Guide*. For more information on the AWS Step Functions Data Science SDK APIs, see: https://aws-step-functions-data-science-sdk.readthedocs.io. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Choice state\n",
    "\n",
    "A `Choice` state in Step Functions adds branching logic to your workflow. See [Choice](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/states.html#stepfunctions.steps.states.Choice) in the AWS Step Functions Data Science SDK documentation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "choice_state = Choice(\n",
    "    state_id=\"Is this Hello World example?\"\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First create the steps for the \"happy path\"."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Wait state\n",
    "\n",
    "A `Wait` state in Step Functions waits a specific amount of time. See [Wait](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/states.html#stepfunctions.steps.states.Wait) in the AWS Step Functions Data Science SDK documentation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "wait_state = Wait(\n",
    "    state_id=\"Wait for 3 seconds\",\n",
    "    seconds=3\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Parallel state\n",
    "\n",
    "A `Parallel` state in Step Functions is used to create parallel branches of execution in your workflow. This creates the `Parallel` step and adds two branches: `Hello` and `World`. See [Parallel](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/states.html#stepfunctions.steps.states.Parallel) in the AWS Step Functions Data Science SDK documentation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "parallel_state = Parallel(\"MyParallelState\")\n",
    "parallel_state.add_branch(\n",
    "    Pass(state_id=\"Hello\")\n",
    ")\n",
    "parallel_state.add_branch(\n",
    "    Pass(state_id=\"World\")\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lambda Task state\n",
    "\n",
    "A `Task` State in Step Functions represents a single unit of work performed by a workflow. Tasks can call Lambda functions and orchestrate other AWS services. See [AWS Service Integrations](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-service-integrations.html) in the *AWS Step Functions Developer Guide*.\n",
    "\n",
    "#### Create a Lambda function\n",
    "\n",
    "**Remember to select Python when you create the Lambda function!**\n",
    "\n",
    "The Lambda task state in this workflow uses a simple Lambda function **(Python 3.x)** that returns a base64 encoded string. Create the following function in the [Lambda console](https://console.aws.amazon.com/lambda/).\n",
    "\n",
    "```python\n",
    "import json\n",
    "import base64\n",
    " \n",
    "def lambda_handler(event, context):\n",
    "    return {\n",
    "        'statusCode': 200,\n",
    "        'input': event['input'],\n",
    "        'output': base64.b64encode(event['input'].encode()).decode('UTF-8')\n",
    "    }\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Define the Lambda Task state\n",
    "\n",
    "The following creates a [LambdaStep](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/compute.html#stepfunctions.steps.compute.LambdaStep) called `lambda_state`, and then configures the options to [Retry](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html#error-handling-retrying-after-an-error) if the Lambda function fails."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "lambda_state = LambdaStep(\n",
    "    state_id=\"Convert HelloWorld to Base64\",\n",
    "    parameters={  \n",
    "        \"FunctionName\": \"datascience-sdk2\", #replace with the name of the function you created\n",
    "        \"Payload\": {  \n",
    "           \"input\": \"HelloWorld\"\n",
    "        }\n",
    "    }\n",
    ")\n",
    "\n",
    "lambda_state.add_retry(Retry(\n",
    "    error_equals=[\"States.TaskFailed\"],\n",
    "    interval_seconds=15,\n",
    "    max_attempts=2,\n",
    "    backoff_rate=4.0\n",
    "))\n",
    "\n",
    "lambda_state.add_catch(Catch(\n",
    "    error_equals=[\"States.TaskFailed\"],\n",
    "    next_step=Fail(\"LambdaTaskFailed\")\n",
    "))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Succeed state\n",
    "\n",
    "A `Succeed` state in Step Functions stops an execution successfully. See [Succeed](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/states.html#stepfunctions.steps.states.Succeed) in the AWS Step Functions Data Science SDK documentation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "succeed_state = Succeed(\"HelloWorldSuccessful\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Chain together steps for the happy path\n",
    "\n",
    "The following cell links together the steps you've created above into a sequential group called `happy_path`. The new path sequentially includes the Wait state, the Parallel state, the Lambda state, and the Succeed state that you created earlier.\n",
    "\n",
    "After chaining together the steps for the happy path, we will define the workflow and visualize the happy path."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "happy_path = Chain([wait_state, parallel_state, lambda_state, succeed_state])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://do0of8uwbahzz.cloudfront.net/graph.css\">\n",
       "<div id=\"graph-431\" class=\"workflowgraph\">\n",
       "    \n",
       "    <svg></svg>\n",
       "    \n",
       "</div>\n",
       "\n",
       "<script type=\"text/javascript\">\n",
       "\n",
       "require.config({\n",
       "    paths: {\n",
       "        sfn: \"https://do0of8uwbahzz.cloudfront.net/sfn\",\n",
       "    }\n",
       "});\n",
       "\n",
       "require(['sfn'], function(sfn) {\n",
       "    var options = {\n",
       "        width: $('#graph-431').width(),\n",
       "        height: 600,\n",
       "        layout: 'LR',\n",
       "        resizeHeight: true\n",
       "    };\n",
       "\n",
       "    var definition = {\"StartAt\": \"Wait for 3 seconds\", \"States\": {\"Wait for 3 seconds\": {\"Seconds\": 3, \"Type\": \"Wait\", \"Next\": \"MyParallelState\"}, \"MyParallelState\": {\"Type\": \"Parallel\", \"Next\": \"Convert HelloWorld to Base64\", \"Branches\": [{\"StartAt\": \"Hello\", \"States\": {\"Hello\": {\"Type\": \"Pass\", \"End\": true}}}, {\"StartAt\": \"World\", \"States\": {\"World\": {\"Type\": \"Pass\", \"End\": true}}}]}, \"Convert HelloWorld to Base64\": {\"Parameters\": {\"FunctionName\": \"datascience-sdk2\", \"Payload\": {\"input\": \"HelloWorld\"}}, \"Resource\": \"arn:aws:states:::lambda:invoke\", \"Type\": \"Task\", \"Next\": \"HelloWorldSuccessful\", \"Retry\": [{\"ErrorEquals\": [\"States.TaskFailed\"], \"IntervalSeconds\": 15, \"MaxAttempts\": 2, \"BackoffRate\": 4.0}], \"Catch\": [{\"ErrorEquals\": [\"States.TaskFailed\"], \"Next\": \"LambdaTaskFailed\"}]}, \"HelloWorldSuccessful\": {\"Type\": \"Succeed\"}, \"LambdaTaskFailed\": {\"Type\": \"Fail\"}}};\n",
       "    var elementId = '#graph-431';\n",
       "\n",
       "    var graph = new sfn.StateMachineGraph(definition, elementId, options);\n",
       "    graph.render();\n",
       "});\n",
       "\n",
       "</script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Next, we define the workflow\n",
    "happy_workflow = Workflow(\n",
    "    name=\"MyWorkflow_Happy\",\n",
    "    definition=happy_path,\n",
    "    role=workflow_execution_role\n",
    ")\n",
    "\n",
    "happy_workflow.render_graph()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For the sad path, we simply end the workflow using a `Fail` state. See [Fail](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/states.html#stepfunctions.steps.states.Fail) in the AWS Step Functions Data Science SDK documentation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "sad_state = Fail(\"HelloWorldFailed\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Choice state\n",
    "\n",
    "Now, attach branches to the Choice state you created earlier. See *Choice Rules* in the [AWS Step Functions Data Science SDK documentation](https://aws-step-functions-data-science-sdk.readthedocs.io) ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "choice_state.add_choice(\n",
    "    rule=ChoiceRule.BooleanEquals(variable=start_pass_state.output()[\"IsHelloWorldExample\"], value=True),\n",
    "    next_step=happy_path\n",
    ")\n",
    "choice_state.add_choice(\n",
    "    ChoiceRule.BooleanEquals(variable=start_pass_state.output()[\"IsHelloWorldExample\"], value=False),\n",
    "    next_step=sad_state\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Chain together two steps\n",
    "\n",
    "In the next cell, you will chain the start_pass_state with the choice_state and define the workflow."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# First we chain the start pass state and the choice state\n",
    "branching_workflow_definition=Chain([start_pass_state, choice_state])\n",
    "\n",
    "# Next, we define the workflow\n",
    "branching_workflow = Workflow(\n",
    "    name=\"MyWorkflow_v3\",\n",
    "    definition=branching_workflow_definition,\n",
    "    role=workflow_execution_role\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "    \"StartAt\": \"MyPassState\",\n",
      "    \"States\": {\n",
      "        \"MyPassState\": {\n",
      "            \"Type\": \"Pass\",\n",
      "            \"Next\": \"Is this Hello World example?\"\n",
      "        },\n",
      "        \"Is this Hello World example?\": {\n",
      "            \"Type\": \"Choice\",\n",
      "            \"Choices\": [\n",
      "                {\n",
      "                    \"Variable\": \"$['IsHelloWorldExample']\",\n",
      "                    \"BooleanEquals\": true,\n",
      "                    \"Next\": \"Wait for 3 seconds\"\n",
      "                },\n",
      "                {\n",
      "                    \"Variable\": \"$['IsHelloWorldExample']\",\n",
      "                    \"BooleanEquals\": false,\n",
      "                    \"Next\": \"HelloWorldFailed\"\n",
      "                }\n",
      "            ]\n",
      "        },\n",
      "        \"Wait for 3 seconds\": {\n",
      "            \"Seconds\": 3,\n",
      "            \"Type\": \"Wait\",\n",
      "            \"Next\": \"MyParallelState\"\n",
      "        },\n",
      "        \"MyParallelState\": {\n",
      "            \"Type\": \"Parallel\",\n",
      "            \"Next\": \"Convert HelloWorld to Base64\",\n",
      "            \"Branches\": [\n",
      "                {\n",
      "                    \"StartAt\": \"Hello\",\n",
      "                    \"States\": {\n",
      "                        \"Hello\": {\n",
      "                            \"Type\": \"Pass\",\n",
      "                            \"End\": true\n",
      "                        }\n",
      "                    }\n",
      "                },\n",
      "                {\n",
      "                    \"StartAt\": \"World\",\n",
      "                    \"States\": {\n",
      "                        \"World\": {\n",
      "                            \"Type\": \"Pass\",\n",
      "                            \"End\": true\n",
      "                        }\n",
      "                    }\n",
      "                }\n",
      "            ]\n",
      "        },\n",
      "        \"Convert HelloWorld to Base64\": {\n",
      "            \"Parameters\": {\n",
      "                \"FunctionName\": \"datascience-sdk2\",\n",
      "                \"Payload\": {\n",
      "                    \"input\": \"HelloWorld\"\n",
      "                }\n",
      "            },\n",
      "            \"Resource\": \"arn:aws:states:::lambda:invoke\",\n",
      "            \"Type\": \"Task\",\n",
      "            \"Next\": \"HelloWorldSuccessful\",\n",
      "            \"Retry\": [\n",
      "                {\n",
      "                    \"ErrorEquals\": [\n",
      "                        \"States.TaskFailed\"\n",
      "                    ],\n",
      "                    \"IntervalSeconds\": 15,\n",
      "                    \"MaxAttempts\": 2,\n",
      "                    \"BackoffRate\": 4.0\n",
      "                }\n",
      "            ],\n",
      "            \"Catch\": [\n",
      "                {\n",
      "                    \"ErrorEquals\": [\n",
      "                        \"States.TaskFailed\"\n",
      "                    ],\n",
      "                    \"Next\": \"LambdaTaskFailed\"\n",
      "                }\n",
      "            ]\n",
      "        },\n",
      "        \"HelloWorldSuccessful\": {\n",
      "            \"Type\": \"Succeed\"\n",
      "        },\n",
      "        \"LambdaTaskFailed\": {\n",
      "            \"Type\": \"Fail\"\n",
      "        },\n",
      "        \"HelloWorldFailed\": {\n",
      "            \"Type\": \"Fail\"\n",
      "        }\n",
      "    }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "# Review the Amazon States Language code for your workflow\n",
    "print(branching_workflow.definition.to_json(pretty=True))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Review a visualization for your workflow\n",
    "\n",
    "The following cell generates a graphical representation of your workflow."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://do0of8uwbahzz.cloudfront.net/graph.css\">\n",
       "<div id=\"graph-304\" class=\"workflowgraph\">\n",
       "    \n",
       "    <svg></svg>\n",
       "    \n",
       "</div>\n",
       "\n",
       "<script type=\"text/javascript\">\n",
       "\n",
       "require.config({\n",
       "    paths: {\n",
       "        sfn: \"https://do0of8uwbahzz.cloudfront.net/sfn\",\n",
       "    }\n",
       "});\n",
       "\n",
       "require(['sfn'], function(sfn) {\n",
       "    var options = {\n",
       "        width: $('#graph-304').width(),\n",
       "        height: 600,\n",
       "        layout: 'LR',\n",
       "        resizeHeight: true\n",
       "    };\n",
       "\n",
       "    var definition = {\"StartAt\": \"MyPassState\", \"States\": {\"MyPassState\": {\"Type\": \"Pass\", \"Next\": \"Is this Hello World example?\"}, \"Is this Hello World example?\": {\"Type\": \"Choice\", \"Choices\": [{\"Variable\": \"$['IsHelloWorldExample']\", \"BooleanEquals\": true, \"Next\": \"Wait for 3 seconds\"}, {\"Variable\": \"$['IsHelloWorldExample']\", \"BooleanEquals\": false, \"Next\": \"HelloWorldFailed\"}]}, \"Wait for 3 seconds\": {\"Seconds\": 3, \"Type\": \"Wait\", \"Next\": \"MyParallelState\"}, \"MyParallelState\": {\"Type\": \"Parallel\", \"Next\": \"Convert HelloWorld to Base64\", \"Branches\": [{\"StartAt\": \"Hello\", \"States\": {\"Hello\": {\"Type\": \"Pass\", \"End\": true}}}, {\"StartAt\": \"World\", \"States\": {\"World\": {\"Type\": \"Pass\", \"End\": true}}}]}, \"Convert HelloWorld to Base64\": {\"Parameters\": {\"FunctionName\": \"datascience-sdk2\", \"Payload\": {\"input\": \"HelloWorld\"}}, \"Resource\": \"arn:aws:states:::lambda:invoke\", \"Type\": \"Task\", \"Next\": \"HelloWorldSuccessful\", \"Retry\": [{\"ErrorEquals\": [\"States.TaskFailed\"], \"IntervalSeconds\": 15, \"MaxAttempts\": 2, \"BackoffRate\": 4.0}], \"Catch\": [{\"ErrorEquals\": [\"States.TaskFailed\"], \"Next\": \"LambdaTaskFailed\"}]}, \"HelloWorldSuccessful\": {\"Type\": \"Succeed\"}, \"LambdaTaskFailed\": {\"Type\": \"Fail\"}, \"HelloWorldFailed\": {\"Type\": \"Fail\"}}};\n",
       "    var elementId = '#graph-304';\n",
       "\n",
       "    var graph = new sfn.StateMachineGraph(definition, elementId, options);\n",
       "    graph.render();\n",
       "});\n",
       "\n",
       "</script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "branching_workflow.render_graph(portrait=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create the workflow and execute\n",
    "\n",
    "In the next cells, we will create the branching happy workflow in AWS Step Functions with [create](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Workflow.create) and execute it with [execute](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Workflow.execute).\n",
    "\n",
    "Since IsHelloWorldExample is set to True, your execution should follow the happy path."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32m[INFO] Workflow created successfully on AWS Step Functions.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'arn:aws:states:us-east-1:806570384721:stateMachine:MyWorkflow_v3'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "branching_workflow.create()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32m[INFO] Workflow execution started successfully on AWS Step Functions.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "branching_workflow_execution = branching_workflow.execute(inputs={\n",
    "        \"IsHelloWorldExample\": True\n",
    "})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Review the progress\n",
    "\n",
    "Review the workflow progress with the [render_progress](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Execution.render_progress).\n",
    "\n",
    "Review the execution history by calling [list_events](https://aws-step-functions-data-science-sdk.readthedocs.io/en/latest/workflow.html#stepfunctions.workflow.Execution.list_events) to list all events in the workflow execution."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://do0of8uwbahzz.cloudfront.net/graph.css\">\n",
       "<div id=\"graph-946\" class=\"workflowgraph\">\n",
       "    \n",
       "    <style>\n",
       "        .graph-legend ul {\n",
       "            list-style-type: none;\n",
       "            padding: 10px;\n",
       "            padding-left: 0;\n",
       "            margin: 0;\n",
       "            position: absolute;\n",
       "            top: 0;\n",
       "            background: transparent;\n",
       "        }\n",
       "\n",
       "        .graph-legend li {\n",
       "            margin-left: 10px;\n",
       "            display: inline-block;\n",
       "        }\n",
       "\n",
       "        .graph-legend li > div {\n",
       "            width: 10px;\n",
       "            height: 10px;\n",
       "            display: inline-block;\n",
       "        }\n",
       "\n",
       "        .graph-legend .success { background-color: #2BD62E }\n",
       "        .graph-legend .failed { background-color: #DE322F }\n",
       "        .graph-legend .cancelled { background-color: #DDDDDD }\n",
       "        .graph-legend .in-progress { background-color: #53C9ED }\n",
       "        .graph-legend .caught-error { background-color: #FFA500 }\n",
       "    </style>\n",
       "    <div class=\"graph-legend\">\n",
       "        <ul>\n",
       "            <li>\n",
       "                <div class=\"success\"></div>\n",
       "                <span>Success</span>\n",
       "            </li>\n",
       "            <li>\n",
       "                <div class=\"failed\"></div>\n",
       "                <span>Failed</span>\n",
       "            </li>\n",
       "            <li>\n",
       "                <div class=\"cancelled\"></div>\n",
       "                <span>Cancelled</span>\n",
       "            </li>\n",
       "            <li>\n",
       "                <div class=\"in-progress\"></div>\n",
       "                <span>In Progress</span>\n",
       "            </li>\n",
       "            <li>\n",
       "                <div class=\"caught-error\"></div>\n",
       "                <span>Caught Error</span>\n",
       "            </li>\n",
       "        </ul>\n",
       "    </div>\n",
       "\n",
       "    <svg></svg>\n",
       "    <a href=\"https://console.aws.amazon.com/states/home?region=us-east-1#/executions/details/arn:aws:states:us-east-1:806570384721:execution:MyWorkflow_v3:321fdf3d-ddc4-47fe-901d-ec217ea3264f\" target=\"_blank\"> Inspect in AWS Step Functions </a>\n",
       "</div>\n",
       "\n",
       "<script type=\"text/javascript\">\n",
       "\n",
       "require.config({\n",
       "    paths: {\n",
       "        sfn: \"https://do0of8uwbahzz.cloudfront.net/sfn\",\n",
       "    }\n",
       "});\n",
       "\n",
       "require(['sfn'], function(sfn) {\n",
       "    var options = {\n",
       "        width: $('#graph-946').width(),\n",
       "        height: 1000,\n",
       "        layout: 'LR',\n",
       "        resizeHeight: true\n",
       "    };\n",
       "\n",
       "    var definition = {\"StartAt\": \"MyPassState\", \"States\": {\"MyPassState\": {\"Type\": \"Pass\", \"Next\": \"Is this Hello World example?\"}, \"Is this Hello World example?\": {\"Type\": \"Choice\", \"Choices\": [{\"Variable\": \"$['IsHelloWorldExample']\", \"BooleanEquals\": true, \"Next\": \"Wait for 3 seconds\"}, {\"Variable\": \"$['IsHelloWorldExample']\", \"BooleanEquals\": false, \"Next\": \"HelloWorldFailed\"}]}, \"Wait for 3 seconds\": {\"Seconds\": 3, \"Type\": \"Wait\", \"Next\": \"MyParallelState\"}, \"MyParallelState\": {\"Type\": \"Parallel\", \"Next\": \"Convert HelloWorld to Base64\", \"Branches\": [{\"StartAt\": \"Hello\", \"States\": {\"Hello\": {\"Type\": \"Pass\", \"End\": true}}}, {\"StartAt\": \"World\", \"States\": {\"World\": {\"Type\": \"Pass\", \"End\": true}}}]}, \"Convert HelloWorld to Base64\": {\"Parameters\": {\"FunctionName\": \"datascience-sdk2\", \"Payload\": {\"input\": \"HelloWorld\"}}, \"Resource\": \"arn:aws:states:::lambda:invoke\", \"Type\": \"Task\", \"Next\": \"HelloWorldSuccessful\", \"Retry\": [{\"ErrorEquals\": [\"States.TaskFailed\"], \"IntervalSeconds\": 15, \"MaxAttempts\": 2, \"BackoffRate\": 4.0}], \"Catch\": [{\"ErrorEquals\": [\"States.TaskFailed\"], \"Next\": \"LambdaTaskFailed\"}]}, \"HelloWorldSuccessful\": {\"Type\": \"Succeed\"}, \"LambdaTaskFailed\": {\"Type\": \"Fail\"}, \"HelloWorldFailed\": {\"Type\": \"Fail\"}}};\n",
       "    var elementId = '#graph-946';\n",
       "    var events = { 'events': [{\"timestamp\": 1579010592.327, \"type\": \"ExecutionStarted\", \"id\": 1, \"previousEventId\": 0, \"executionStartedEventDetails\": {\"input\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\", \"roleArn\": \"arn:aws:iam::806570384721:role/StepFunctionsExecutionRole\"}}, {\"timestamp\": 1579010592.349, \"type\": \"PassStateEntered\", \"id\": 2, \"previousEventId\": 0, \"stateEnteredEventDetails\": {\"name\": \"MyPassState\", \"input\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010592.349, \"type\": \"PassStateExited\", \"id\": 3, \"previousEventId\": 2, \"stateExitedEventDetails\": {\"name\": \"MyPassState\", \"output\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010592.45, \"type\": \"ChoiceStateEntered\", \"id\": 4, \"previousEventId\": 3, \"stateEnteredEventDetails\": {\"name\": \"Is this Hello World example?\", \"input\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010592.45, \"type\": \"ChoiceStateExited\", \"id\": 5, \"previousEventId\": 4, \"stateExitedEventDetails\": {\"name\": \"Is this Hello World example?\", \"output\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010592.551, \"type\": \"WaitStateEntered\", \"id\": 6, \"previousEventId\": 5, \"stateEnteredEventDetails\": {\"name\": \"Wait for 3 seconds\", \"input\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010595.552, \"type\": \"WaitStateExited\", \"id\": 7, \"previousEventId\": 6, \"stateExitedEventDetails\": {\"name\": \"Wait for 3 seconds\", \"output\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010595.56, \"type\": \"ParallelStateEntered\", \"id\": 8, \"previousEventId\": 7, \"stateEnteredEventDetails\": {\"name\": \"MyParallelState\", \"input\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010595.56, \"type\": \"ParallelStateStarted\", \"id\": 9, \"previousEventId\": 8}, {\"timestamp\": 1579010595.661, \"type\": \"PassStateEntered\", \"id\": 10, \"previousEventId\": 9, \"stateEnteredEventDetails\": {\"name\": \"Hello\", \"input\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010595.661, \"type\": \"PassStateExited\", \"id\": 11, \"previousEventId\": 10, \"stateExitedEventDetails\": {\"name\": \"Hello\", \"output\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010595.668, \"type\": \"PassStateEntered\", \"id\": 12, \"previousEventId\": 9, \"stateEnteredEventDetails\": {\"name\": \"World\", \"input\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010595.668, \"type\": \"PassStateExited\", \"id\": 13, \"previousEventId\": 12, \"stateExitedEventDetails\": {\"name\": \"World\", \"output\": \"{\\n    \\\"IsHelloWorldExample\\\": true\\n}\"}}, {\"timestamp\": 1579010595.668, \"type\": \"ParallelStateSucceeded\", \"id\": 14, \"previousEventId\": 13}, {\"timestamp\": 1579010595.668, \"type\": \"ParallelStateExited\", \"id\": 15, \"previousEventId\": 13, \"stateExitedEventDetails\": {\"name\": \"MyParallelState\", \"output\": \"[{\\n    \\\"IsHelloWorldExample\\\": true\\n},{\\n    \\\"IsHelloWorldExample\\\": true\\n}]\"}}, {\"timestamp\": 1579010595.674, \"type\": \"TaskStateEntered\", \"id\": 16, \"previousEventId\": 15, \"stateEnteredEventDetails\": {\"name\": \"Convert HelloWorld to Base64\", \"input\": \"[{\\n    \\\"IsHelloWorldExample\\\": true\\n},{\\n    \\\"IsHelloWorldExample\\\": true\\n}]\"}}, {\"timestamp\": 1579010595.674, \"type\": \"TaskScheduled\", \"id\": 17, \"previousEventId\": 16, \"taskScheduledEventDetails\": {\"resourceType\": \"lambda\", \"resource\": \"invoke\", \"region\": \"us-east-1\", \"parameters\": \"{\\\"FunctionName\\\":\\\"datascience-sdk2\\\",\\\"Payload\\\":{\\\"input\\\":\\\"HelloWorld\\\"}}\"}}, {\"timestamp\": 1579010595.702, \"type\": \"TaskStarted\", \"id\": 18, \"previousEventId\": 17, \"taskStartedEventDetails\": {\"resourceType\": \"lambda\", \"resource\": \"invoke\"}}, {\"timestamp\": 1579010595.977, \"type\": \"TaskSucceeded\", \"id\": 19, \"previousEventId\": 18, \"taskSucceededEventDetails\": {\"resourceType\": \"lambda\", \"resource\": \"invoke\", \"output\": \"{\\\"ExecutedVersion\\\":\\\"$LATEST\\\",\\\"Payload\\\":{\\\"statusCode\\\":200,\\\"input\\\":\\\"HelloWorld\\\",\\\"output\\\":\\\"SGVsbG9Xb3JsZA==\\\"},\\\"SdkHttpMetadata\\\":{\\\"HttpHeaders\\\":{\\\"Connection\\\":\\\"keep-alive\\\",\\\"Content-Length\\\":\\\"72\\\",\\\"Content-Type\\\":\\\"application/json\\\",\\\"Date\\\":\\\"Tue, 14 Jan 2020 14:03:15 GMT\\\",\\\"X-Amz-Executed-Version\\\":\\\"$LATEST\\\",\\\"x-amzn-Remapped-Content-Length\\\":\\\"0\\\",\\\"x-amzn-RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\",\\\"X-Amzn-Trace-Id\\\":\\\"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\\\"},\\\"HttpStatusCode\\\":200},\\\"SdkResponseMetadata\\\":{\\\"RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\"},\\\"StatusCode\\\":200}\"}}, {\"timestamp\": 1579010595.977, \"type\": \"TaskStateExited\", \"id\": 20, \"previousEventId\": 19, \"stateExitedEventDetails\": {\"name\": \"Convert HelloWorld to Base64\", \"output\": \"{\\\"ExecutedVersion\\\":\\\"$LATEST\\\",\\\"Payload\\\":{\\\"statusCode\\\":200,\\\"input\\\":\\\"HelloWorld\\\",\\\"output\\\":\\\"SGVsbG9Xb3JsZA==\\\"},\\\"SdkHttpMetadata\\\":{\\\"HttpHeaders\\\":{\\\"Connection\\\":\\\"keep-alive\\\",\\\"Content-Length\\\":\\\"72\\\",\\\"Content-Type\\\":\\\"application/json\\\",\\\"Date\\\":\\\"Tue, 14 Jan 2020 14:03:15 GMT\\\",\\\"X-Amz-Executed-Version\\\":\\\"$LATEST\\\",\\\"x-amzn-Remapped-Content-Length\\\":\\\"0\\\",\\\"x-amzn-RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\",\\\"X-Amzn-Trace-Id\\\":\\\"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\\\"},\\\"HttpStatusCode\\\":200},\\\"SdkResponseMetadata\\\":{\\\"RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\"},\\\"StatusCode\\\":200}\"}}, {\"timestamp\": 1579010595.985, \"type\": \"SucceedStateEntered\", \"id\": 21, \"previousEventId\": 20, \"stateEnteredEventDetails\": {\"name\": \"HelloWorldSuccessful\", \"input\": \"{\\\"ExecutedVersion\\\":\\\"$LATEST\\\",\\\"Payload\\\":{\\\"statusCode\\\":200,\\\"input\\\":\\\"HelloWorld\\\",\\\"output\\\":\\\"SGVsbG9Xb3JsZA==\\\"},\\\"SdkHttpMetadata\\\":{\\\"HttpHeaders\\\":{\\\"Connection\\\":\\\"keep-alive\\\",\\\"Content-Length\\\":\\\"72\\\",\\\"Content-Type\\\":\\\"application/json\\\",\\\"Date\\\":\\\"Tue, 14 Jan 2020 14:03:15 GMT\\\",\\\"X-Amz-Executed-Version\\\":\\\"$LATEST\\\",\\\"x-amzn-Remapped-Content-Length\\\":\\\"0\\\",\\\"x-amzn-RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\",\\\"X-Amzn-Trace-Id\\\":\\\"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\\\"},\\\"HttpStatusCode\\\":200},\\\"SdkResponseMetadata\\\":{\\\"RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\"},\\\"StatusCode\\\":200}\"}}, {\"timestamp\": 1579010595.985, \"type\": \"SucceedStateExited\", \"id\": 22, \"previousEventId\": 21, \"stateExitedEventDetails\": {\"name\": \"HelloWorldSuccessful\", \"output\": \"{\\\"ExecutedVersion\\\":\\\"$LATEST\\\",\\\"Payload\\\":{\\\"statusCode\\\":200,\\\"input\\\":\\\"HelloWorld\\\",\\\"output\\\":\\\"SGVsbG9Xb3JsZA==\\\"},\\\"SdkHttpMetadata\\\":{\\\"HttpHeaders\\\":{\\\"Connection\\\":\\\"keep-alive\\\",\\\"Content-Length\\\":\\\"72\\\",\\\"Content-Type\\\":\\\"application/json\\\",\\\"Date\\\":\\\"Tue, 14 Jan 2020 14:03:15 GMT\\\",\\\"X-Amz-Executed-Version\\\":\\\"$LATEST\\\",\\\"x-amzn-Remapped-Content-Length\\\":\\\"0\\\",\\\"x-amzn-RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\",\\\"X-Amzn-Trace-Id\\\":\\\"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\\\"},\\\"HttpStatusCode\\\":200},\\\"SdkResponseMetadata\\\":{\\\"RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\"},\\\"StatusCode\\\":200}\"}}, {\"timestamp\": 1579010595.985, \"type\": \"ExecutionSucceeded\", \"id\": 23, \"previousEventId\": 22, \"executionSucceededEventDetails\": {\"output\": \"{\\\"ExecutedVersion\\\":\\\"$LATEST\\\",\\\"Payload\\\":{\\\"statusCode\\\":200,\\\"input\\\":\\\"HelloWorld\\\",\\\"output\\\":\\\"SGVsbG9Xb3JsZA==\\\"},\\\"SdkHttpMetadata\\\":{\\\"HttpHeaders\\\":{\\\"Connection\\\":\\\"keep-alive\\\",\\\"Content-Length\\\":\\\"72\\\",\\\"Content-Type\\\":\\\"application/json\\\",\\\"Date\\\":\\\"Tue, 14 Jan 2020 14:03:15 GMT\\\",\\\"X-Amz-Executed-Version\\\":\\\"$LATEST\\\",\\\"x-amzn-Remapped-Content-Length\\\":\\\"0\\\",\\\"x-amzn-RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\",\\\"X-Amzn-Trace-Id\\\":\\\"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\\\"},\\\"HttpStatusCode\\\":200},\\\"SdkResponseMetadata\\\":{\\\"RequestId\\\":\\\"cb610f86-339a-4782-a03c-d22530a2b182\\\"},\\\"StatusCode\\\":200}\"}}] };\n",
       "\n",
       "    var graph = new sfn.StateMachineExecutionGraph(definition, events, elementId, options);\n",
       "    graph.render();\n",
       "});\n",
       "\n",
       "</script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "branching_workflow_execution.render_progress()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <style>\n",
       "        \n",
       "    .table-widget {\n",
       "        width: 100%;\n",
       "        font-size: 14px;\n",
       "        line-height: 28px;\n",
       "        color: #545b64;\n",
       "        border-spacing: 0;\n",
       "        background-color: #fff;\n",
       "        border-color: grey;\n",
       "        background: #fafafa;\n",
       "    }\n",
       "\n",
       "    .table-widget thead th {\n",
       "        text-align: left !important;\n",
       "        color: #879596;\n",
       "        padding: 0.3em 2em;\n",
       "        border-bottom: 1px solid #eaeded;\n",
       "        min-height: 4rem;\n",
       "        line-height: 28px;\n",
       "    }\n",
       "\n",
       "    .table-widget thead th:first-of-type {\n",
       "    }\n",
       "\n",
       "    .table-widget td {\n",
       "        overflow-wrap: break-word;\n",
       "        padding: 0.4em 2em;\n",
       "        line-height: 28px;\n",
       "        text-align: left !important;\n",
       "        background: #fff;\n",
       "        border-bottom: 1px solid #eaeded;\n",
       "        border-top: 1px solid transparent;\n",
       "    }\n",
       "\n",
       "    .table-widget td:before {\n",
       "        content: \"\";\n",
       "        height: 3rem;\n",
       "    }\n",
       "\n",
       "    a {\n",
       "        cursor: pointer;\n",
       "        text-decoration: none !important;\n",
       "        color: #007dbc;\n",
       "    }\n",
       "\n",
       "    a:hover {\n",
       "        text-decoration: underline !important;\n",
       "    }\n",
       "\n",
       "    a.disabled {\n",
       "        color: black;\n",
       "        cursor: default;\n",
       "        pointer-events: none;\n",
       "    }\n",
       "\n",
       "    .hide {\n",
       "        display: none;\n",
       "    }\n",
       "\n",
       "    pre {\n",
       "        white-space: pre-wrap;\n",
       "    }\n",
       "\n",
       "        \n",
       "    .table-widget .clickable-cell {\n",
       "        padding-left: 0.1em;\n",
       "        cursor: pointer;\n",
       "    }\n",
       "\n",
       "    .toggle-icon {\n",
       "        display: inline-block;\n",
       "        width: 0;\n",
       "        height: 0;\n",
       "        border-top: 5px solid transparent;\n",
       "        border-left: 8px solid #545b64;\n",
       "        border-bottom: 5px solid transparent;\n",
       "        margin-right: 5px;\n",
       "    }\n",
       "\n",
       "    .toggle-icon.open {\n",
       "        -webkit-transform: rotate(90deg);\n",
       "        -ms-transform: rotate(90deg);\n",
       "        transform: rotate(90deg);\n",
       "    }\n",
       "\n",
       "    </style>\n",
       "    <table class=\"table-widget\">\n",
       "        <thead>\n",
       "            <tr>\n",
       "                <th style=\"width: 60px\">ID</th>\n",
       "                <th>Type</th>\n",
       "                <th>Step</th>\n",
       "                <th>Resource</th>\n",
       "                <th>Elapsed Time (ms)</th>\n",
       "                <th>Timestamp</th>\n",
       "            </tr>\n",
       "        </thead>\n",
       "        <tbody>\n",
       "            \n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>1</span>\n",
       "        </td>\n",
       "        <td>ExecutionStarted</td>\n",
       "        <td></td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>0.0</td>\n",
       "        <td>Jan 14, 2020 02:03:12.327 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"input\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    },\n",
       "    \"roleArn\": \"arn:aws:iam::806570384721:role/StepFunctionsExecutionRole\"\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>2</span>\n",
       "        </td>\n",
       "        <td>PassStateEntered</td>\n",
       "        <td>MyPassState</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>22.0</td>\n",
       "        <td>Jan 14, 2020 02:03:12.349 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"MyPassState\",\n",
       "    \"input\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>3</span>\n",
       "        </td>\n",
       "        <td>PassStateExited</td>\n",
       "        <td>MyPassState</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>22.0</td>\n",
       "        <td>Jan 14, 2020 02:03:12.349 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"MyPassState\",\n",
       "    \"output\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>4</span>\n",
       "        </td>\n",
       "        <td>ChoiceStateEntered</td>\n",
       "        <td>Is this Hello World example?</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>123.0</td>\n",
       "        <td>Jan 14, 2020 02:03:12.450 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"Is this Hello World example?\",\n",
       "    \"input\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>5</span>\n",
       "        </td>\n",
       "        <td>ChoiceStateExited</td>\n",
       "        <td>Is this Hello World example?</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>123.0</td>\n",
       "        <td>Jan 14, 2020 02:03:12.450 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"Is this Hello World example?\",\n",
       "    \"output\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>6</span>\n",
       "        </td>\n",
       "        <td>WaitStateEntered</td>\n",
       "        <td>Wait for 3 seconds</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>224.0</td>\n",
       "        <td>Jan 14, 2020 02:03:12.551 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"Wait for 3 seconds\",\n",
       "    \"input\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>7</span>\n",
       "        </td>\n",
       "        <td>WaitStateExited</td>\n",
       "        <td>Wait for 3 seconds</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>225.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.552 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"Wait for 3 seconds\",\n",
       "    \"output\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>8</span>\n",
       "        </td>\n",
       "        <td>ParallelStateEntered</td>\n",
       "        <td>MyParallelState</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>233.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.560 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"MyParallelState\",\n",
       "    \"input\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>9</span>\n",
       "        </td>\n",
       "        <td>ParallelStateStarted</td>\n",
       "        <td>MyParallelState</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>233.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.560 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>10</span>\n",
       "        </td>\n",
       "        <td>PassStateEntered</td>\n",
       "        <td>Hello</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>334.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.661 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"Hello\",\n",
       "    \"input\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>11</span>\n",
       "        </td>\n",
       "        <td>PassStateExited</td>\n",
       "        <td>Hello</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>334.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.661 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"Hello\",\n",
       "    \"output\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>12</span>\n",
       "        </td>\n",
       "        <td>PassStateEntered</td>\n",
       "        <td>World</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>341.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.668 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"World\",\n",
       "    \"input\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>13</span>\n",
       "        </td>\n",
       "        <td>PassStateExited</td>\n",
       "        <td>World</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>341.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.668 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"World\",\n",
       "    \"output\": {\n",
       "        \"IsHelloWorldExample\": true\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>14</span>\n",
       "        </td>\n",
       "        <td>ParallelStateSucceeded</td>\n",
       "        <td>World</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>341.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.668 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>15</span>\n",
       "        </td>\n",
       "        <td>ParallelStateExited</td>\n",
       "        <td>MyParallelState</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>341.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.668 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"MyParallelState\",\n",
       "    \"output\": [\n",
       "        {\n",
       "            \"IsHelloWorldExample\": true\n",
       "        },\n",
       "        {\n",
       "            \"IsHelloWorldExample\": true\n",
       "        }\n",
       "    ]\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>16</span>\n",
       "        </td>\n",
       "        <td>TaskStateEntered</td>\n",
       "        <td>Convert HelloWorld to Base64</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>347.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.674 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"Convert HelloWorld to Base64\",\n",
       "    \"input\": [\n",
       "        {\n",
       "            \"IsHelloWorldExample\": true\n",
       "        },\n",
       "        {\n",
       "            \"IsHelloWorldExample\": true\n",
       "        }\n",
       "    ]\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>17</span>\n",
       "        </td>\n",
       "        <td>TaskScheduled</td>\n",
       "        <td>Convert HelloWorld to Base64</td>\n",
       "        <td><a class='disabled' target=\"_blank\">Step Functions execution</a></td>\n",
       "        <td>347.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.674 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"resourceType\": \"lambda\",\n",
       "    \"resource\": \"invoke\",\n",
       "    \"region\": \"us-east-1\",\n",
       "    \"parameters\": {\n",
       "        \"FunctionName\": \"datascience-sdk2\",\n",
       "        \"Payload\": {\n",
       "            \"input\": \"HelloWorld\"\n",
       "        }\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>18</span>\n",
       "        </td>\n",
       "        <td>TaskStarted</td>\n",
       "        <td>Convert HelloWorld to Base64</td>\n",
       "        <td><a class='disabled' target=\"_blank\">Step Functions execution</a></td>\n",
       "        <td>375.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.702 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"resourceType\": \"lambda\",\n",
       "    \"resource\": \"invoke\"\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>19</span>\n",
       "        </td>\n",
       "        <td>TaskSucceeded</td>\n",
       "        <td>Convert HelloWorld to Base64</td>\n",
       "        <td><a class='disabled' target=\"_blank\">Step Functions execution</a></td>\n",
       "        <td>650.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.977 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"resourceType\": \"lambda\",\n",
       "    \"resource\": \"invoke\",\n",
       "    \"output\": {\n",
       "        \"ExecutedVersion\": \"$LATEST\",\n",
       "        \"Payload\": {\n",
       "            \"statusCode\": 200,\n",
       "            \"input\": \"HelloWorld\",\n",
       "            \"output\": \"SGVsbG9Xb3JsZA==\"\n",
       "        },\n",
       "        \"SdkHttpMetadata\": {\n",
       "            \"HttpHeaders\": {\n",
       "                \"Connection\": \"keep-alive\",\n",
       "                \"Content-Length\": \"72\",\n",
       "                \"Content-Type\": \"application/json\",\n",
       "                \"Date\": \"Tue, 14 Jan 2020 14:03:15 GMT\",\n",
       "                \"X-Amz-Executed-Version\": \"$LATEST\",\n",
       "                \"x-amzn-Remapped-Content-Length\": \"0\",\n",
       "                \"x-amzn-RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\",\n",
       "                \"X-Amzn-Trace-Id\": \"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\"\n",
       "            },\n",
       "            \"HttpStatusCode\": 200\n",
       "        },\n",
       "        \"SdkResponseMetadata\": {\n",
       "            \"RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\"\n",
       "        },\n",
       "        \"StatusCode\": 200\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>20</span>\n",
       "        </td>\n",
       "        <td>TaskStateExited</td>\n",
       "        <td>Convert HelloWorld to Base64</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>650.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.977 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"Convert HelloWorld to Base64\",\n",
       "    \"output\": {\n",
       "        \"ExecutedVersion\": \"$LATEST\",\n",
       "        \"Payload\": {\n",
       "            \"statusCode\": 200,\n",
       "            \"input\": \"HelloWorld\",\n",
       "            \"output\": \"SGVsbG9Xb3JsZA==\"\n",
       "        },\n",
       "        \"SdkHttpMetadata\": {\n",
       "            \"HttpHeaders\": {\n",
       "                \"Connection\": \"keep-alive\",\n",
       "                \"Content-Length\": \"72\",\n",
       "                \"Content-Type\": \"application/json\",\n",
       "                \"Date\": \"Tue, 14 Jan 2020 14:03:15 GMT\",\n",
       "                \"X-Amz-Executed-Version\": \"$LATEST\",\n",
       "                \"x-amzn-Remapped-Content-Length\": \"0\",\n",
       "                \"x-amzn-RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\",\n",
       "                \"X-Amzn-Trace-Id\": \"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\"\n",
       "            },\n",
       "            \"HttpStatusCode\": 200\n",
       "        },\n",
       "        \"SdkResponseMetadata\": {\n",
       "            \"RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\"\n",
       "        },\n",
       "        \"StatusCode\": 200\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>21</span>\n",
       "        </td>\n",
       "        <td>SucceedStateEntered</td>\n",
       "        <td>HelloWorldSuccessful</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>658.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.985 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"HelloWorldSuccessful\",\n",
       "    \"input\": {\n",
       "        \"ExecutedVersion\": \"$LATEST\",\n",
       "        \"Payload\": {\n",
       "            \"statusCode\": 200,\n",
       "            \"input\": \"HelloWorld\",\n",
       "            \"output\": \"SGVsbG9Xb3JsZA==\"\n",
       "        },\n",
       "        \"SdkHttpMetadata\": {\n",
       "            \"HttpHeaders\": {\n",
       "                \"Connection\": \"keep-alive\",\n",
       "                \"Content-Length\": \"72\",\n",
       "                \"Content-Type\": \"application/json\",\n",
       "                \"Date\": \"Tue, 14 Jan 2020 14:03:15 GMT\",\n",
       "                \"X-Amz-Executed-Version\": \"$LATEST\",\n",
       "                \"x-amzn-Remapped-Content-Length\": \"0\",\n",
       "                \"x-amzn-RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\",\n",
       "                \"X-Amzn-Trace-Id\": \"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\"\n",
       "            },\n",
       "            \"HttpStatusCode\": 200\n",
       "        },\n",
       "        \"SdkResponseMetadata\": {\n",
       "            \"RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\"\n",
       "        },\n",
       "        \"StatusCode\": 200\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>22</span>\n",
       "        </td>\n",
       "        <td>SucceedStateExited</td>\n",
       "        <td>HelloWorldSuccessful</td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>658.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.985 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"name\": \"HelloWorldSuccessful\",\n",
       "    \"output\": {\n",
       "        \"ExecutedVersion\": \"$LATEST\",\n",
       "        \"Payload\": {\n",
       "            \"statusCode\": 200,\n",
       "            \"input\": \"HelloWorld\",\n",
       "            \"output\": \"SGVsbG9Xb3JsZA==\"\n",
       "        },\n",
       "        \"SdkHttpMetadata\": {\n",
       "            \"HttpHeaders\": {\n",
       "                \"Connection\": \"keep-alive\",\n",
       "                \"Content-Length\": \"72\",\n",
       "                \"Content-Type\": \"application/json\",\n",
       "                \"Date\": \"Tue, 14 Jan 2020 14:03:15 GMT\",\n",
       "                \"X-Amz-Executed-Version\": \"$LATEST\",\n",
       "                \"x-amzn-Remapped-Content-Length\": \"0\",\n",
       "                \"x-amzn-RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\",\n",
       "                \"X-Amzn-Trace-Id\": \"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\"\n",
       "            },\n",
       "            \"HttpStatusCode\": 200\n",
       "        },\n",
       "        \"SdkResponseMetadata\": {\n",
       "            \"RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\"\n",
       "        },\n",
       "        \"StatusCode\": 200\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "\n",
       "    <tr class=\"awsui-table-row\">\n",
       "        <td class=\"awsui-util-pl-xs clickable-cell\">\n",
       "            <div class=\"toggle-icon\"></div>\n",
       "            <span>23</span>\n",
       "        </td>\n",
       "        <td>ExecutionSucceeded</td>\n",
       "        <td></td>\n",
       "        <td><a class='disabled' target=\"_blank\">-</a></td>\n",
       "        <td>658.0</td>\n",
       "        <td>Jan 14, 2020 02:03:15.985 PM</td>\n",
       "    </tr>\n",
       "    <tr class=\"hide\">\n",
       "        <td class=\"execution-event-detail\" colspan=\"6\">\n",
       "            <pre>{\n",
       "    \"output\": {\n",
       "        \"ExecutedVersion\": \"$LATEST\",\n",
       "        \"Payload\": {\n",
       "            \"statusCode\": 200,\n",
       "            \"input\": \"HelloWorld\",\n",
       "            \"output\": \"SGVsbG9Xb3JsZA==\"\n",
       "        },\n",
       "        \"SdkHttpMetadata\": {\n",
       "            \"HttpHeaders\": {\n",
       "                \"Connection\": \"keep-alive\",\n",
       "                \"Content-Length\": \"72\",\n",
       "                \"Content-Type\": \"application/json\",\n",
       "                \"Date\": \"Tue, 14 Jan 2020 14:03:15 GMT\",\n",
       "                \"X-Amz-Executed-Version\": \"$LATEST\",\n",
       "                \"x-amzn-Remapped-Content-Length\": \"0\",\n",
       "                \"x-amzn-RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\",\n",
       "                \"X-Amzn-Trace-Id\": \"root=1-5e1dca23-59164766fb429893b21e82aa;sampled=0\"\n",
       "            },\n",
       "            \"HttpStatusCode\": 200\n",
       "        },\n",
       "        \"SdkResponseMetadata\": {\n",
       "            \"RequestId\": \"cb610f86-339a-4782-a03c-d22530a2b182\"\n",
       "        },\n",
       "        \"StatusCode\": 200\n",
       "    }\n",
       "}</pre>\n",
       "        </td>\n",
       "    </tr>\n",
       "\n",
       "        </tbody>\n",
       "    </table>\n",
       "    <script type=\"text/javascript\">\n",
       "        \n",
       "    var clickableCells = document.getElementsByClassName(\"clickable-cell\");\n",
       "    for (var cell of clickableCells) {\n",
       "        cell.addEventListener(\"click\", function(e) {\n",
       "            var currentRow = e.srcElement.closest(\"tr\");\n",
       "            var toggleRow = currentRow.nextElementSibling;\n",
       "            var toggleArrow = currentRow.getElementsByClassName(\"toggle-icon\")[0];\n",
       "\n",
       "            toggleRow.classList.toggle(\"hide\");\n",
       "            toggleArrow.classList.toggle(\"open\");\n",
       "        });\n",
       "    }\n",
       "\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "branching_workflow_execution.list_events(html=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "conda_python3",
   "language": "python",
   "name": "conda_python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
